package com.example.demo.mapper;


import com.example.demo.entity.*;
import org.apache.ibatis.annotations.*;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface UserMapper {

//    @Select("select * from runoob_tbl")
//    List<Table_demo> findAll();
//
//    @Update("INSERT INTO runoob_tbl (runoob_id, runoob_title, runoob_author, submission_date) VALUES (#{runoob_id},#{runoob_title},#{runoob_author},#{submission_date})")
//    @Transactional
//    void save(Table_demo table_demo);
//
//    @Select("select * from runoob_tbl order by runoob_id desc limit 1")
//    Table_demo findLast();

    @Select("select * from #{name}")
    String selectTable(@Param("name") String name);

    @Select("select * from accept_info")
    List<AcceptInfo> find_all_accept_info();

    @Select("select * from courier_basic_info")
    List<CourierBasicInfo> find_all_courier_basic_info();

    @Select("select * from courier_info")
    List<CourierInfo> find_all_courier_info();

    @Select("select * from order_basic_info")
    List<OrderBasicInfo> find_all_order_basic_info();

    @Select("select * from send_info")
    List<SendInfo> find_all_send_info();

    @Select("select * from user_basic_info")
    List<UserBasicInfo> find_all_user_basic_info();

    @Select("select * from user_common_info")
    List<UserCommonInfo> find_all_user_common_info();

    @Select("select * from user_common_info limit 1")
    UserCommonInfo find_last_user_common_info();

    @Select("select * from user_common_info where user_id in (select user_id from user_basic_info where user_phone = #{myphone})")
    List<UserCommonInfo> find_my_user_common_info(@Param("myphone") String myphone);

    @Select("select * from accept_info where accept_id in (select user_id from user_basic_info where user_phone = #{myphone})")
    List<AcceptInfo> find_my_accept_info(@Param("myphone") String myphone);

    @Select("select * from send_info where sender_id in (select user_id from user_basic_info where user_phone = #{myphone})")
    List<SendInfo> find_my_send_info(@Param("myphone") String myphone);

    @Delete("delete from user_common_info where user_id = #{id} and user_common_phone = #{phone}")
    int delete_my_user_common_info(@Param("id") String _id,@Param("phone") String phone);

    @Update("update user_common_info" +
            "    set user_common_name = #{user_common_name}," +
            "      user_common_address = #{user_common_address}"+
            "    where user_id = #{user_id} and user_common_phone = #{user_common_phone}")
    int update_my_user_common_info(UserCommonInfo userCommonInfo);

    @Insert({ "insert into user_common_info(user_id, user_common_name, user_common_phone, user_common_address)" +
            " values(#{user_id}, #{user_common_name}, #{user_common_phone}, #{user_common_address})" })
    int insert_my_user_common_info(UserCommonInfo userCommonInfo);


    @Select("select user_id from user_basic_info where user_phone = #{phone}")
    String get_user_id(@Param("phone") String phone);
}
